package com.project.weather.controller;

import com.project.weather.common.AResultCode;
import com.project.weather.common.PageBean;
import com.project.weather.common.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import io.swagger.annotations.*;
import com.project.weather.pojo.CityBean;
import com.project.weather.service.CityService;

/**
 *<p>Title:CityController.java</p>
 *<p>Description:城市表 Action</p>
 *@author xxx
 *@version 1.0
 *@Automatically generate by Coder in 2022-02-13 20:49
 */
@RestController
@RequestMapping(name="城市表", value="/city/")
@Api(tags = {"城市表 Api 接口文档"})
public class CityController {
	private static final Logger log = LoggerFactory.getLogger(CityController.class);
	@Autowired
	private CityService cityService;

	@ApiOperation(value="新增接口")
	@Transactional
	@RequestMapping(name="新增接口",value="insert.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, CityBean> insert(@ApiParam(value = "对象数据", required = true) @RequestBody CityBean bean){
		return cityService.insert(bean);
	}

	@ApiOperation(value="修改接口")
	@Transactional
	@RequestMapping(name="修改接口",value="update.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, CityBean> update(@ApiParam(value = "对象数据", required = true) @RequestBody CityBean bean){
		return cityService.update(bean);
	}

	@ApiOperation(value="删除接口")
	@ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="删除接口",value="delete.json",method = RequestMethod.GET)
	@Transactional
	public ResultMap<AResultCode, CityBean> delete(@RequestParam("id") String id){
		return cityService.delete(id);
	}

	@ApiOperation(value="分页查询列表接口")
	@RequestMapping(name="分页查询列表接口",value="pageList.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, PageBean<CityBean>> pageList(@ApiParam(value = "分页对象数据", required = true) @RequestBody PageBean<CityBean> pb){
		pb.init(pb,CityBean.class);	//需要调用init，将页面传来的json条件转换为bean
		return cityService.pageList(pb);
	}

	@ApiOperation(value="查询所有数据接口")
	@RequestMapping(name="查询所有数据接口",value="list.json",method = RequestMethod.POST)
	public ResultMap<AResultCode, List<CityBean>> list(@ApiParam(value = "对象数据", required = true) @RequestBody(required = false) CityBean bean){
		return cityService.list(bean);
	}

	@ApiOperation(value="根据主键获取数据接口")
	@ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "query")
	@RequestMapping(name="根据主键获取数据接口",value="get.json",method = RequestMethod.GET)
	public ResultMap<AResultCode, CityBean> get(String id){
		return cityService.get(id);
	}
	
}